package cn.zyzpp.service.resume.impl;

import cn.zyzpp.dao.CampusDao;
import cn.zyzpp.entity.resume.Campus;
import cn.zyzpp.service.resume.CampusService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 活动
 * Create by yster@foxmail.com 2018/5/21/021 22:32
 */
@Service
@CacheConfig(cacheNames = {"CampusService"})
public class CampusServiceImpl implements CampusService {
    @Autowired
    private CampusDao campusDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(Campus campus, int uid) {
        campus.setUid(uid);
        campus.setC_describe(StringUtil.symline(campus.getC_describe()));
        campusDao.save(campus);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delect(int id) {
        campusDao.deleteAllById(id);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataByUid(Campus campus) {
        Campus campus1 = campusDao.findByUid(campus.getUid());
        campus.setC_describe(StringUtil.symline(campus.getC_describe()));
        campus1.updata(campus);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<Campus> queryAll(int uid) {
        return campusDao.findAllByUid(uid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public Campus query(int uid) {
        return campusDao.findByUid(uid);
    }
}
